package cn.sylinx.hbatis.ext.transaction.guice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import cn.sylinx.hbatis.ext.transaction.AbstractTransactionalSupport;
import cn.sylinx.hbatis.ext.transaction.Transactional;
import cn.sylinx.hbatis.log.GLog;

public class TransactionalInterceptor extends AbstractTransactionalSupport implements MethodInterceptor {

	@Override
	public Object invoke(MethodInvocation invocation) throws Throwable {
		GLog.debug("TransactionalInterceptor bingo");

		return transaction(invocation.getMethod().getAnnotation(Transactional.class), () -> invocation.proceed());
	}

}
